<?php
Yii::import('application.components.dao.class.Dao');

class AuctionDetailDao extends Dao
{

    public function attributeLabels()
    {
        return array(
            'title' => 'Auction Title',
            'winner_price' => 'Initial Auction Price',
            'winner_price_increment' => 'Bidding Increment'
        );
    }

    public function dataSource()
    {
        return array(
            'AuctionInfo' => array(
                'attributes' => array(
                    'id',
                    'title',
                    'tag',
                    'short_description',
                    'description',
                    'created',
                    'winner_price_increment',
                    'winner_price',
                    'start_time',
                    'end_time',
                    'status',
                    'winner_id'
                )
            ),
            'AuctionPool' => array(
                'attributes' => array(
                    'start_time',
                    'end_time'
                )
            ),
            'AuctionFee' => array(
                'attributes' => array(
                    'value_price',
                    'auction_fee',
                    'shipping_fee',
                    'billing_fee',
                    'autobid_startprice'
                )
            ),
            'AuctionParame' => array(
                'attributes' => array(
                    'meta_title',
                    'meta_keywords',
                    'url',
                    'meta_description',
                    'rookie',
                    'show',
                    'bin',
                    'type',
                    'giftcard'
                )
            ),
            'AuctionCategoryRelations' => array(
                'attributes' => array(
                    'category_id',
                    'category_title'
                )
            ),
            'AuctionProductRelations' => array(
                'attributes' => array(
                    'product_id',
                    'product_title'
                )
            ),
            'AuctionResourceDao' => array(
                'attributes' => array(
                    'images'
                )
            ),
            'Customer' => array(
                'attributes' => array(
                    'user_name'
                )
            ),
            'CustomerInfo' => array(
                'attributes' => array(
                    'avatar'
                )
            )
        );
    }

    public function rules()
    {
        return array(
            array(
                'category_title',
                'exist',
                'className' => 'Category',
                'attributeName' => 'title',
                'message' => 'Category is not find!'
            ),
            array(
                'product_title',
                'exist',
                'className' => 'ProductInfo',
                'attributeName' => 'title',
                'message' => 'Product is not find!'
            ),
            array(
                'category_title,value_price,auction_fee,shipping_fee,billing_fee',
                'required'
            ),
            array(
                'value_price,auction_fee,shipping_fee,billing_fee',
                'numerical'
            ),
            array(
                'start_date,end_date',
                'required',
                'on' => 'create'
            )
        );
    }

    public function dataSourceRelations()
    {
        return array(
            'AuctionInfo' => array(
                'AuctionPool' => array(
                    'part',
                    'join' => array(
                        'id' => 'auction_id'
                    )
                ),
                'AuctionFee' => array(
                    'part',
                    'join' => array(
                        'id' => 'auction_id'
                    )
                ),
                'AuctionParame' => array(
                    'part',
                    'join' => array(
                        'id' => 'auction_id'
                    )
                ),
                'AuctionCategoryRelations' => array(
                    'part',
                    'join' => array(
                        'id' => 'auction_id'
                    )
                ),
                'AuctionProductRelations' => array(
                    'part',
                    'join' => array(
                        'id' => 'auction_id'
                    )
                ),
                'AuctionResourceDao' => array(
                    'part',
                    'join' => array(
                        'id' => 'auction_id'
                    )
                ),
                'Customer' => array(
                    'part',
                    'join' => array(
                        'winner_id' => 'id'
                    )
                ),
                'CustomerInfo' => array(
                    'part',
                    'join' => array(
                        'winner_id' => 'customer_id'
                    )
                )
            )
        );
    }
}